﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Library.DomainObject.Administration;
using SIPO.Library.DataAccess.Administration;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using System.Configuration;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Web.Support;
using SIPO.Library.DomainObject.Administration.UserManagement;

namespace SIPO.Web.Forms.Transaction
{
    public partial class recDevolutionform : SIPO.Web.BasePage
    {
        protected override void OnLoad(EventArgs e)
        {
            int id = 0;

            if (!IsPostBack)
            {
                if (Request.Params["DevolutionID"] != null)
                {
                    id = int.Parse(Request.Params["DevolutionID"].ToString());
                }

                recDevolutionRepo recDevolutionDal = new recDevolutionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                List<recDebtor> debtors = null;

                debtors = recDevolutionDal.GetDebtorForRecDevolution();

                ddlDebtorName.Items.Clear();

                debtors.ForEach(delegate(recDebtor debtor)
                {
                    ddlDebtorName.Items.Add(new ListItem(debtor.DebtorCode + '-' + debtor.DebtorName, debtor.DebtorID.ToString()));
                });
                ddlDebtorName.Items.Insert(0, new ListItem("-- pilih nama debitur  --", string.Empty));

                hfId.Value = id.ToString();

                //ambil data recDevolution
                if (id > 0)
                {
                    recDevolution devolution = recDevolutionDal.GetById(id);

                    ddlDebtorName.Items.FindByValue(devolution.DebtorID.ToString()).Selected = true;
                    txtDebtorId.Text = devolution.DebtorID.ToString();
                    txtLetterNo.Text = devolution.LetterNo.ToString();
                    txtLetterDate.Text = devolution.LetterDate.Value.ToString("dd/MM/yyyy");
                    txtDevolutionDate.Text = devolution.DevolutionDate.Value.ToString("dd/MM/yyyy");
                    txtDevolutionValues.Text = devolution.DevolutionValues.ToString();
                    txtCatatan.Text = devolution.Note.ToString();
                    hfId.Value = id.ToString();
                    hfDemandNo.Value = devolution.DemandNo.ToString();
                }
            }
        }
    }
}